package LeetCode;

import Constructs.ListNode;

//
// Created by ✎﹏ℳ๓独赏☆独醉 on 2024/6/17.
// 
public class 反转链表 {
    public static void main(String[] args) {
        System.out.println(reverseList(new ListNode(1, new ListNode(2, new ListNode(3, new ListNode(4, new ListNode(5, null)))))));
    }
    public static ListNode reverseList(ListNode head) {
        if(head == null || head.next == null)return head;
        ListNode newHead = reverseList(head.next);
        head.next.next = head;
        head.next = null;
        return newHead;
    }

}
